home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / UUSUB.C < prev    next >
C/C++ Source or Header  |  1991-06-27  |  7KB  |  202 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u s t a t . c                                                 */
  3. /*                                                                    */
  4. /*    Report summary of UUPC activity                                 */
  5. /*                                                                    */
  6. /*    Copyright (C) 1991, Andrew H. Derbyshire                        */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. #include <assert.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <time.h>
  13.  
  14. #include "lib.h"
  15. #include "hostable.h"
  16. #include "dater.h"
  17. #include "hostatus.h"
  18. #include "security.h"
  19. #include "timestmp.h"
  20.  
  21. /*--------------------------------------------------------------------*/
  22. /*                            Local macros                            */
  23. /*--------------------------------------------------------------------*/
  24.  
  25. #define line( a, b, c, d, e, f, g, h, i, j ) \
  26.       printf("%-8.8s %-6.6s %-11.11s %-11.11s %5.5s %5.5s %5.5s %5.5s %5.5s %5.5s\n" ,\
  27.       a, b, c, d, e, f, g, h, i ,j )
  28.  
  29. /*--------------------------------------------------------------------*/
  30. /*                        Internal prototypes                         */
  31. /*--------------------------------------------------------------------*/
  32.  
  33. static void showhost( struct HostTable *host);
  34. static char *when( time_t t );
  35. static char *status( hostatus current_status );
  36. static char *format( long l);
  37.  
  38. /*--------------------------------------------------------------------*/
  39. /*                          Global variables                          */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. static char output[10 * 12];
  43. static size_t column ;
  44.  
  45. currentfile();
  46.  
  47. /*--------------------------------------------------------------------*/
  48. /*                            main program                            */
  49. /*--------------------------------------------------------------------*/
  50.  
  51. #ifdef __TURBOC__
  52. #pragma argsused
  53. #endif
  54.  
  55. void main( int argc , char **argv)
  56. {
  57.  
  58.    struct HostTable *host;
  59.    boolean firsthost = TRUE;
  60.    static const char *dashes = "-----------";
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*               Announce ourselves to a waiting world                */
  64. /*--------------------------------------------------------------------*/
  65.  
  66.    debuglevel = 0;
  67.  
  68. #if defined(__CORE__)
  69.    copywrong = strdup(copyright);
  70.    checkref(copywrong);
  71. #endif
  72.    banner( argv );
  73.  
  74. /*--------------------------------------------------------------------*/
  75. /*       Load system configuration and then the UUPC host stats       */
  76. /*--------------------------------------------------------------------*/
  77.  
  78.    assert (configure( B_UUCP ));
  79.    HostStatus();
  80.  
  81.    printf("Host information collected since %s\n",ctime( &start_stats ));
  82.  
  83.    line("Host","Host ",  "Date Last",  "Last Conn","Secs" , "Bytes", "Bytes",
  84.          "Files", "Files", "Total");
  85.    line("Name","Status ","Connected ","Attempt", "Conn",  "Sent",  "Recvd",
  86.         "Sent",  "Recvd", "Errs");
  87.    line(dashes,dashes,dashes,dashes,dashes,dashes,dashes,dashes,
  88.          dashes,dashes);
  89.  
  90.    while  ((host = nexthost( firsthost , aliasof )) != BADHOST)
  91.    {
  92.       firsthost = FALSE;
  93.       showhost ( host );
  94.    } /* while */
  95.  
  96. } /* main */
  97.  
  98. /*--------------------------------------------------------------------*/
  99. /*    s h o w h o s t                                                 */
  100. /*                                                                    */
  101. /*    Display information on a single host                            */
  102. /*--------------------------------------------------------------------*/
  103.  
  104. static void showhost( struct HostTable *host)
  105. {
  106.    column = 0;
  107.    checkref( host->hstats );
  108.    line( host->hostname,
  109.       status( host->hstatus ),
  110.       when( host->hstats->lconnect ),
  111.       when( host->hstats->ltime ),
  112.       format( host->hstats->connect ),
  113.       format( host->hstats->bsent ),
  114.       format( host->hstats->breceived ),
  115.       format( host->hstats->fsent ),
  116.       format( host->hstats->freceived ),
  117.       format( host->hstats->errors  ));
  118. }
  119.  
  120. /*--------------------------------------------------------------------*/
  121. /*                            Subroutines                             */
  122. /*--------------------------------------------------------------------*/
  123.  
  124. static char *when( time_t t )
  125. {
  126.    column += 13;
  127.    return dater( t, &output[column]);
  128. }
  129.  
  130. static char *format( long l)
  131. {
  132.    if (l == 0)
  133.       return "";
  134.  
  135.    column += 12;
  136.    if ( l <= 99999)
  137.       sprintf( &output[ column ], "%ld", l);
  138.    else if ( (l/1000) <= 9999)
  139.       sprintf( &output[ column ], "%ldK", l / 1000);
  140.    else
  141.       sprintf( &output[ column ], "%ldM", l / 1000000);
  142.    return &output[column];
  143. }
  144.  
  145. static char *status( hostatus current_status )
  146. {
  147.    switch ( current_status )
  148.    {
  149.       default:
  150.        return "??????";
  151.  
  152.       case  phantom:          /* Entry not fully initialized      */
  153.             return "noinit";
  154.  
  155.       case  localhost:        /* This entry is for ourselves      */
  156.             return "local";
  157.  
  158.       case  routed:           /* This entry is actually a path    */
  159.             return "routed";
  160.  
  161.       case  gatewayed:        /* This entry is delivered to via   */
  162.                               /* an external program on local sys */
  163.             return "gatway";
  164.  
  165.       case  aliasof:          /* This entry is alias of VIA system*/
  166.             return "alias";
  167.  
  168.       case  nocall:           /* real host: never called          */
  169.          return "NEVER";
  170.  
  171.       case  inprogress:       /* Call now active                  */
  172.          return "INPROG";
  173.  
  174.       case  callback_req:     /* System must call us back         */
  175.           return "CALLBK";
  176.  
  177.       case  dial_failed:      /* Hardcoded auto-dial failed       */
  178.          return "NODIAL";
  179.  
  180.       case  script_failed:    /* script in L.SYS failed           */
  181.          return "NSCRPT";
  182.  
  183.       case  max_retry:        /* Have given up calling this sys   */
  184.          return "MAXTRY";
  185.  
  186.       case  too_soon:         /* In retry mode: too soon to call  */
  187.          return "TOSOON";
  188.  
  189.       case  succeeded:        /* self-explanatory                 */
  190.          return "SUCESS";
  191.  
  192.       case  wrong_host:       /* Call out failed: wrong system    */
  193.          return "WRGHST";
  194.  
  195.       case  unknown_host:     /* Call in cailed: unknown system   */
  196.          return "UNKNWN";
  197.  
  198.       case  wrong_time:       /* Unable to call because of time   */
  199.          return "WRGTIM";
  200.    }
  201. }
  202.